module.exports = (sequelize, DataTypes) => {
  const user = sequelize.define('user', {
    nickname: DataTypes.STRING(50), // 昵称可重复
    avatar: DataTypes.STRING(50),
    gender: DataTypes.STRING(10),
    birth: DataTypes.DATE,
    userId: {
      type: DataTypes.STRING(50),
      primaryKey: true
    } // 账号id不可重复
    // email: DataTypes.STRING(50),
    // password: DataTypes.STRING(50),
    // token: DataTypes.STRING(50)
    // phone: DataTypes.STRING(30),
    // country: DataTypes.STRING(20),
    // province: DataTypes.STRING(20),
    // city: DataTypes.STRING(20),
    // birthday: DataTypes.DATE
  })

  user.associate = (models) => {
    user.hasMany(models.userAuth, {
      foreignKey: 'userId',
      sourceKey: 'userId',
      as: 'auths'
    })
    user.hasMany(models.userToken, {
      foreignKey: 'userId',
      sourceKey: 'userId',
      as: 'tokens'
    })
    user.hasMany(models.comment, {
      foreignKey: 'userId',
      sourceKey: 'userId',
      as: 'comments'
    })
  }
  return user
}
